package com.kevin.designpattern.singlenton;

/**
 * 静态内部类实现的单利
 */
public class InnerSingleton {

    public static void main(String[] args) {
        InnerSingleton innerSingleton = new InnerSingleton();
        InnerSingleton instance1 = innerSingleton.getInstance();
        InnerSingleton instance2 = innerSingleton.getInstance();
        System.out.println(instance1 == instance2);

    }

    private InnerSingleton() {
    }

    private static class InnerClassHolder {

        private static final InnerSingleton instance = new InnerSingleton();
    }

    public InnerSingleton getInstance() {
        return InnerClassHolder.instance;
    }

}
